from flask import Flask
from flask_cors import CORS
from app.database import db
from app.routes.cpu import cpu_bp
from app.models import *  # 确保模型被加载


def create_app():
    app = Flask(__name__)

    # 数据库配置
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost/kylin_2025'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SQLALCHEMY_POOL_SIZE'] = 5
    app.config['SQLALCHEMY_POOL_RECYCLE'] = 280

    db.init_app(app)
    CORS(app)

    # 注册蓝图
    app.register_blueprint(cpu_bp)

    return app
